Strict Alteration

Strict Alternation Approach is the software mechanism implemented at user mode. It is a busy waiting solution which can be implemented only for two processes. In this approach, A turn variable is used which is actually a lock. This approach can only be used for only two processes. In general, let the two processes be P0 and P1. They share a variable called turn variable. The execution of the algorithm can be seen in following steps

Buttons overview

Turn Box : Displays the value of turn variable (which process turn is there to go in critical section).
Process0 : On clicking this button P0 process will move forward.
Process1 : On clicking this button P1 process will move forward.
EndP0 : If P0 is in critical section then on clicking this button it will end the process and comeback to non critical section.
EndP1 : If P1 is in critical section then on clicking this button it will end the process and comeback to non critical section.
Reset : The page will be reloaded.

How to execute: Step 1

Press Process0 as we can see turn is for P0 so it will move P0 into critical section.

Step 2

Now if P1 is ready to go in critical section then press Process1 which will check will turn is for P1 or not. If not then it will move P1 in while loop till P0 completes its execution.

Step 3

As execution of P0 is over press EndP0 to move it in non critical section and chage the value of turn variable to P1.

Step 4

As critical section is empty and P1 is ready in while and its P1's turn press Process1 to move P1 in critical section.

Step 5

Now if P0 is again reay to be executed then press Process0 but critical section is not empty and P1 turn is there so P0 will move to while loop.

Step 6

As P1 completes its execution press EndP1 to move it to non critical section and press Process0 to move P0 in critical section as turn variable is showing value P0 and critical section is empty.

Alert message

If value to turn variable is P0 and you press Process1 then it will show an alert message that "turn is for process 0".(Condition: Both processes should be non critical section).

Alert message

If value to turn variable is P1 and you press Process0 then it will show an alert message that "turn is for process 1".(Condition: Both processes should be non critical section).

Analysis of Strict Alternation approach

1.Mutual Exclusion

The strict alternation approach provides mutual exclusion in every case. This procedure works only for two processes. The pseudo code is different for both of the processes. The process will only enter when it sees that the turn variable is equal to its Process ID otherwise not Hence No process can enter in the critical section regardless of its turn.

2.Progress

Progress is not guaranteed in this mechanism. If P0 doesn't want to get enter into the critical section on its turn then P1 got blocked for infinite time. P1 has to wait for so long for its turn since the turn variable will remain 0 until P0 assigns it to 1.

3.Portability

The solution provides portability. It is a pure software mechanism implemented at user mode and doesn't need any special instruction from the Operating System.


abc